package com.eltonkent.dashboard.util;

import java.io.File;

import android.os.StatFs;

public final class SDCardInfo {
	/**
	 * Get the SDcard directory
	 * 
	 * @return The sdcard directory
	 */
	public static File getDirectory() {
		return android.os.Environment.getExternalStorageDirectory();
	}

	/**
	 * Get the free space on the SDcard
	 * 
	 * @return the free space on SDCard in bytes
	 */
	public static long getFreeSpace() {
		StatFs cardStatistics = new StatFs(getDirectory().toString());
		long freeSpace = (long) cardStatistics.getBlockSize()
				* cardStatistics.getFreeBlocks();
		return freeSpace;
	}

	/**
	 * Total space on the SDcard that is available to applications
	 * 
	 * @return total space on SDCard
	 */
	public static long getTotalSpace() {

		StatFs cardStatistics = new StatFs(getDirectory().toString());
		return cardStatistics.getBlockSize()
				* cardStatistics.getAvailableBlocks();
	}

	/**
	 * Check if the device has an SDcard.
	 * 
	 * @return
	 */
	public static boolean isMounted() {
		return android.os.Environment.getExternalStorageState().equals(
				android.os.Environment.MEDIA_MOUNTED);
	}

	/**
	 * Checks if the given path is readable
	 * 
	 * @param file
	 *            file instance
	 * @return true if the path is readable
	 */
	public static boolean isReadable(File file) {
		return file.canRead();
	}

	/**
	 * Checks if the file path is writable
	 * 
	 * @param file
	 *            The fil
	 * @return true if the path is writable
	 */
	public static boolean isWritable(File file) {
		return file.canWrite();
	}

}
